package com.forestar.xzk.threadFor;

import android.app.Dialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import java.io.File;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * created by  xzk
 * 2020/7/23   18:21
 * 说明:  线程的规范使用范例
 */
public class ThreadUseUtils {

    /**
     *Administrator
     *2020/7/23
     * useThreadForFeasure
     * 日常使用线程，通过线程1等待线程2执行完毕，线程1获取线程2的jieguo
     *  使用范例
     **/
    public static void useThreadForFeasure(){
        Callable<String> callable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                //do something
                return "";
            }
        };
        FutureTask futureTask = new FutureTask(callable);
        Thread workThread = new Thread(futureTask);
        workThread.start();
        // 得到任务执行的结果
        try {
            String msg = (String) futureTask.get();
            int maxLength = 1300;
            if(!TextUtils.isEmpty(msg) && msg.length()>maxLength){
                msg = msg.substring(0,maxLength);
            }

        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
